package com.member.shop.service.impl;

import java.util.List;

import com.member.common.utils.DateUtils;

import javax.annotation.Resource;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.shop.service.ISysBizNotifyUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.member.shop.mapper.SysBizNotifyMapper;
import com.member.shop.domain.SysBizNotify;
import com.member.shop.service.ISysBizNotifyService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 公告通知Service业务层处理
 *
 * @author lixinchen
 * @date 2024-11-05
 */
@Service
public class SysBizNotifyServiceImpl extends ServiceImpl<SysBizNotifyMapper, SysBizNotify> implements ISysBizNotifyService {
    @Resource
    private SysBizNotifyMapper sysBizNotifyMapper;

    /**
     * 查询公告通知
     *
     * @param id 公告通知主键
     * @return 公告通知
     */
    @Override
    public SysBizNotify selectSysBizNotifyById(Long id) {
        return sysBizNotifyMapper.selectById(id);
    }

    /**
     * 查询公告通知列表
     *
     * @param queryWrapper 公告通知
     * @return 公告通知
     */
    @Override
    public List<SysBizNotify> selectSysBizNotifyList(LambdaQueryWrapper<SysBizNotify> queryWrapper) {
        return sysBizNotifyMapper.selectList(queryWrapper);
    }

    @Override
    public List<SysBizNotify> selectSysBizNotifyList(SysBizNotify sysBizNotify) {
        return sysBizNotifyMapper.selectSysBizNotifyList(sysBizNotify);
    }

    /**
     * 新增公告通知
     *
     * @param sysBizNotify 公告通知
     * @return 结果
     */
    @Override
    public int insertSysBizNotify(SysBizNotify sysBizNotify) {
        sysBizNotify.setCreateTime(DateUtils.getNowDate());
        return sysBizNotifyMapper.insert(sysBizNotify);
    }

    /**
     * 修改公告通知
     *
     * @param sysBizNotify 公告通知
     * @return 结果
     */
    @Override
    public int updateSysBizNotify(SysBizNotify sysBizNotify) {
        sysBizNotify.setUpdateTime(DateUtils.getNowDate());
        return sysBizNotifyMapper.updateById(sysBizNotify);
    }

    /**
     * 批量删除公告通知
     *
     * @param ids 需要删除的公告通知主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteSysBizNotifyByIds(Long[] ids) {
        for (Long id : ids) {
            deleteSysBizNotifyById(id);

        }

        return ids.length;
    }



    @Autowired
    private ISysBizNotifyUserService notifyUserService;

    /**
     * 删除公告通知信息
     *
     * @param id 公告通知主键
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteSysBizNotifyById(Long id) {
        notifyUserService.deleteSysBizNotifyUserByNotifyId(id);

        return sysBizNotifyMapper.deleteById(id);
    }

    @Override
    public SysBizNotify queryLastOneByDealerId(Long dealerId) {


        return sysBizNotifyMapper.queryLastOneByDealerId(dealerId, 0);
    }

    @Override
    public SysBizNotify queryLastOneByUserId(Long userId) {


        return sysBizNotifyMapper.queryLastOneByUserId(userId, 0);
    }
}
